package cn.itcast.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.itcast.constant.MessageConstant;
import cn.itcast.dao.MemberDao;
import cn.itcast.entity.PageResult;
import cn.itcast.pojo.Member;
import cn.itcast.service.MemberService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

@Service
@Slf4j
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberDao memberDao;

    /**
     * 根据手机号码查询用户
     *
     * @param phone
     * @return
     */
    @Override
    public Member findByTelephone(String phone) {
        try {
            Member member = this.memberDao.findByTelephone(phone);
            if (ObjectUtil.isNotEmpty(member)) {
                return member;
            }
        } catch (Exception e) {
            log.error(MessageConstant.SERVER_BUSY, e);
        }
        return null;
    }


    /**
     * 分页查询会员信息
     *
     * @param currentPage
     * @param pageSize
     * @param queryString
     * @return
     */
    @Override
    public PageResult SearchInformation(Integer currentPage, Integer pageSize, String queryString) {
        PageHelper.startPage(currentPage, pageSize);
        Page<Member> page = memberDao.selectByList(queryString);
        return new PageResult(page.getTotal(), page.getResult());
    }

    /**
     * 添加会员
     * @param member
     */
    @Override
    public void add(Member member) {
        memberDao.add(member);
    }

    /**
     * 编辑时查询当前用户的信息
     * @param id
     * @return
     */
    @Override
    public Member selectbyid(Integer id) {
        return memberDao.selecebyid(id);
    }

    /**
     * 修改启用停用状态
     * @param id
     * @param status
     * @return
     */
    @Override
    public void updatestatus(Integer id, Integer status) {
        memberDao.updatestatus(id,status);
    }


    /**
     * 修改会员
     * @param member
     */
    @Override
    public void update(Member member) {
        memberDao.update(member);
    }
        /*this.memberDao.add(member);
    }*/
}
